home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / relay / ihave.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-22  |  3.5 KB  |  145 lines

  1. /*
  2.  * Implement the Usenet ihave/sendme control messages, as per RFC 1036. (NCMP)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <ctype.h>
  8. #include <sys/types.h>
  9.  
  10. #include "libc.h"
  11. #include "news.h"
  12. #include "config.h"
  13. #include "batchnames.h"
  14. #include "headers.h"
  15. #include "article.h"
  16. #include "history.h"
  17. #include "fgetmfs.h"
  18. #include "msgs.h"
  19. #include "transmit.h"
  20.  
  21. #ifndef SENDMEDISTR
  22. #define SENDMEDISTR "sendme"    /* kludge: distinguished distribution for sendmes */
  23. #endif
  24. #ifndef IHAVEDISTR
  25. #define IHAVEDISTR "ihave"    /* kludge: distinguished distribution for ihaves */
  26. #endif
  27. #ifndef AVEARTSIZE
  28. #define AVEARTSIZE 3000
  29. #endif
  30. #ifndef SENDMEBATFILE
  31. #define SENDMEBATFILE ".ihave/togo"
  32. #endif
  33. #ifndef SENDITBATFILE
  34. #define SENDITBATFILE ".sendme/togo"
  35. #endif
  36.  
  37. #define PROTO_IHAVE 0
  38. #define PROTO_SENDME 1
  39.  
  40. /* imports */
  41. extern char *ismsgidbad();
  42.  
  43. /* static forwards */
  44. FORWARD void doproto(), procmsgids(), procbodymsgids();
  45. FORWARD statust faketrans();
  46.  
  47. /*
  48.  *    ihave [message-ID-list] remotesys    generate a sendme for remotesys
  49.  *                        from message-ID-list
  50.  * Read message-IDs from args or control message body,
  51.  * look them up in history, post a sendme to to.remotesys (via the batcher
  52.  * to avoid deadlock) consisting of the message-IDs not in history.
  53.  * The "posting" consists of transmitting to a system matching
  54.  * "to.remotesys" in sys, which had better have the I flag on.
  55.  */
  56. void
  57. ihave(args, art)
  58. char *args;
  59. struct article *art;
  60. {
  61.     doproto(args, art, IHAVEDISTR, PROTO_IHAVE);
  62. }
  63.  
  64. /*
  65.  *    sendme [message-ID-list] remotesys    send articles named to remotesys
  66.  * Read message-IDs from args or control message body,
  67.  * transmit the corresponding articles to a system matching
  68.  * "to.remotesys/sendme" in sys, which will typically name a batch file.
  69.  */
  70. void
  71. sendme(args, art)
  72. char *args;
  73. struct article *art;
  74. {
  75.     doproto(args, art, SENDMEDISTR, PROTO_SENDME);
  76. }
  77.  
  78. /*
  79.  * write the name of the article file on the batch file appropriate to
  80.  * this remotesys and protocol.
  81.  */
  82. static void
  83. appmsgnmtonxtbatfile(art, remotesys, proto)
  84. register struct article *art;
  85. char *remotesys;
  86. int proto;
  87. {
  88.     register char *batchname;
  89.     register FILE *batf;
  90.     extern boolean safecmd();
  91.  
  92.     if (!safecmd(remotesys)) {    /* nasty site name? a bit paranoid */
  93.         errno = 0;
  94.         warning("site name `%s' in ihave/sendme is unsafe", remotesys);
  95.         art->a_status |= ST_DROPPED;
  96.         return;
  97.     }
  98.     batchname = str3save(artfile(BTCHDIR), remotesys,
  99.         (proto == PROTO_IHAVE? SENDMEBATFILE: SENDITBATFILE));
  100.     batf = fopenwclex(batchname, "a");
  101.     if (batf != NULL) {
  102.         (void) fputs(art->a_tmpf, batf);
  103.         (void) putc('\n', batf);
  104.         if (fclose(batf) == EOF)
  105.             fulldisk(art, batchname);
  106.     }
  107.     free(batchname);
  108. }
  109.  
  110. /* ARGSUSED distr */
  111. static void
  112. doproto(args, art, distr, proto)
  113. char *args;
  114. register struct article *art;
  115. char *distr;
  116. int proto;
  117. {
  118.     register char *argscp = skipsp(args), *remotesys;
  119.     char *myname;
  120.  
  121.     if (*argscp == '\n' || *argscp == '\0')    /* no args */
  122.         return;
  123.  
  124.     argscp = strsave(argscp);
  125.  
  126.     /* dig out the remote system name */
  127.     remotesys = strrchr(argscp, ' ');    
  128.     if (remotesys == NULL)            /* no msg-ids in command */
  129.         remotesys = argscp;
  130.     else {
  131.         remotesys = argscp + strlen(argscp) - 1;    /* last byte */
  132.         while (isascii(*remotesys) && isspace(*remotesys))
  133.             *remotesys-- = '\0';    /* back up to non-whitespace */
  134.         remotesys = strrchr(argscp, ' ');
  135.         if (remotesys == NULL)        /* no msg-ids in command */
  136.             remotesys = argscp;
  137.         else
  138.             *remotesys++ = '\0';    /* split msg-ids & sys name */
  139.     }
  140.     myname = hostname();
  141.     if (!STREQ(remotesys, myname))        /* remotesys may not be me */
  142.         appmsgnmtonxtbatfile(art, remotesys, proto);
  143.     free(argscp);
  144. }
  145.